#include <iostream>
#include <unistd.h>
#include "blockqueue.hpp"

using namespace std;
void* consumer(void* args)
{
    blockqueue<int>* bq = static_cast<blockqueue<int>*>(args);
    while(true)
    {
        sleep(1);
        int out;
        bq->pop(&out);
        // 处理数据 TODO
        cout << "consumer : I got a message , out->" << out << endl;
        cout << endl;
    }
}

void* productor(void* args)
{
    blockqueue<int>* bq = static_cast<blockqueue<int>*>(args);
    int i = 0;
    while(true)
    {
        int in = i++;
        // 获得数据的处理 TODO
        bq->push(in);
        cout << "productor : I seed a message..." << endl;
    }
}

int main()
{
    pthread_t c[2], q[2];
    blockqueue<int>* bq = new blockqueue<int>();
    pthread_create(&c[0], nullptr, consumer, bq);
    pthread_create(&c[1], nullptr, consumer, bq);
    pthread_create(&q[0], nullptr, productor, bq);
    pthread_create(&q[1], nullptr, productor, bq);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(q[0], nullptr);
    pthread_join(q[1], nullptr);
    return 0;
}